home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.5 Applications 1999 May / SGI IRIX 6.5 Applications 1999 May.iso / dist / arraysvcs.idb / usr / lib / array / aviewh.z / aviewh
Text File  |  1998-10-27  |  2KB  |  106 lines

  1. #!/bin/sh
  2. #
  3. # Simple script to assist "aview"
  4. #
  5.  
  6. usage="Usage: $0 [-i <secs>] [-Z] { top | ps | who | statusonly }"
  7.  
  8. #
  9. # Parse command line options
  10. #
  11. sampleLength=3
  12. skipASHZero=
  13. while getopts "i:Z" curropt; do
  14.     case $curropt in
  15.         i)
  16.         sampleLength=$OPTARG
  17.         ;;
  18.  
  19.         Z)
  20.         skipASHZero="-Z"
  21.         ;;
  22.  
  23.         \?)
  24.         echo $usage
  25.         exit 1
  26.         ;;
  27.  
  28.         *)
  29.         echo "Unexpected results from getopts: $curropt"
  30.         exit 2
  31.         ;;
  32.     esac
  33.     shift `expr $OPTIND - 1`
  34. done
  35.  
  36. #
  37. # Make sure a valid command was specified
  38. #
  39. case $1 in
  40.     top | ps | who | statusonly )
  41.     Cmd=$1
  42.     ;;
  43.  
  44.     * )
  45.     echo "Unrecognized command $1"
  46.     echo $usage
  47.     exit 1
  48.     ;;
  49. esac
  50. shift 1
  51.  
  52. #
  53. # Come up with two temporary files
  54. #
  55. TmpDir=${TMPDIR:-/var/tmp}
  56. if [ ! -w $TmpDir ]; then
  57.     echo "Unable to write into temporary directory $TmpDir"
  58.     exit 2
  59. fi
  60.  
  61. TmpFile1=$TmpDir/aviewh.$$.1
  62. TmpFile2=$TmpDir/aviewh.$$.2
  63. if [ -f $TmpFile1 -o -f $TmpFile2 ]; then
  64.     echo "One or more of these temporary files already exists:"
  65.     echo $TmpFile1
  66.     echo $TmpFile2
  67.     exit 2
  68. fi
  69.  
  70. #
  71. # Go ahead and fire off the first command, astat
  72. #
  73. /usr/sbin/astat -f 4 -i $sampleLength > $TmpFile1 &
  74.  
  75. #
  76. # The other command depends on what was requested
  77. #
  78. case $Cmd in
  79.     top )
  80.     /usr/sbin/atop -f 1 -i $sampleLength $skipASHZero > $TmpFile2 &
  81.     ;;
  82.  
  83.     ps )
  84.     /usr/lib/array/aps localonly $skipASHZero > $TmpFile2 &
  85.     ;;
  86.  
  87.     who )
  88.     /usr/bsd/w | tail +2 > $TmpFile2 &
  89.     ;;
  90.  
  91.     statusonly )
  92.     touch $TmpFile2
  93.     ;;
  94. esac
  95.  
  96. #
  97. # Wait for the two commands to complete
  98. #
  99. wait
  100.  
  101. #
  102. # Display the results and then delete them
  103. #
  104. cat $TmpFile1 $TmpFile2
  105. rm -f $TmpFile1 $TmpFile2
  106.